package reflect;

import reflect.annotations.AutoRunMethod;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class Test4 {
    public static void main(String[] args) throws ClassNotFoundException, InvocationTargetException, IllegalAccessException {
        Class cls=Class.forName("reflect.Person");
        Method[] methods=cls.getMethods();
        for(Method method:methods){
            if (method.isAnnotationPresent(AutoRunMethod.class)){
                AutoRunMethod ar=method.getAnnotation(AutoRunMethod.class);
                int value=ar.value();
                System.out.println("调用"+method.getName()+"方法");
                method.invoke(null,value);
                System.out.println("调用"+method.getName()+"方法结束");
            }
        }
    }
}
